package org.apm.data.delete;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apm.data.bean.Parameter;
import org.apm.data.util.StringUtil;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class DeleteMain {
    private static final Logger LOGGER = LogManager.getLogger(DeleteMain.class);

    public static void main(String[] args) throws InterruptedException {

        if (args.length > 0 && args[0].startsWith("--help")) {
            System.out.println("\t -type, the type of elasticsearch. should be designated. \n"
                    + "\t -i|-ip , masterIp, should be designated. Defaulted \"115.238.29.251\"\n"
                    + "\t -f|-from , the from time , should be '" + Parameter.Day_Pattern + "'\n"
                    + "\t -t|-to , the to time , should be '" + Parameter.Day_Pattern + "'\n"
                    + "\n\n###\tdelete flags, only used in delete.sh\n"
                    + "\t -mType , delete multi type, use the 'types' in properties\n"
                    + "\t -aType , delete all type, which define in code\n"
                    + "\t -deleteUser , delete all the type in elasticsearch, use wildcard inside\n");
            System.exit(0);
        } else {
            Parameter parameter = new Parameter();
            parameter.parameter(args);
            LOGGER.info("[Deleter] parameter: " + parameter);
            if(StringUtil.isEmpty(parameter.getMasterIp())) {
                parameter.setMasterIp(DeleteConfig.CLUSTER_MASTER_IP);
                LOGGER.info("[Deleter] parameter: " + parameter);
            }
            if(!parameter.checkParameter()) {
                LOGGER.info("[Deleter] Should input parameter correctly.");
                System.exit(0);
            }

            DataDeleter deleter = new DataDeleter(parameter);
            deleter.process();
            Thread.sleep(5000);
        }
    }
}
